﻿using Microservice.Shared;
using Microsoft.EntityFrameworkCore;
using ProductService.Entities;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace ProductService.EntityFrameworkCore;

public static class ProductServiceDbContextModelCreatingExtensions
{
    public static void ConfigureProductService(
        this ModelBuilder builder)
    {
        Check.NotNull(builder, nameof(builder));

        builder.Entity<ProductEntity>(b =>
        {
            b.ToTable(ProductServiceDbProperties.DbTablePrefix + "Products", ProductServiceDbProperties.DbSchema);

            b.ConfigureConcurrencyStamp();
            b.ConfigureExtraProperties();
            b.ConfigureAudited();

            b.Property(x => x.Code).IsRequired().HasMaxLength(DatabaseLengthConsts.MaxCodeLength);
            b.Property(x => x.Name).IsRequired().HasMaxLength(DatabaseLengthConsts.MaxNameLength);
            b.Property(x => x.ImageName).HasMaxLength(DatabaseLengthConsts.MaxImageNameLength);

            b.HasIndex(q => q.Code);
            b.HasIndex(q => q.Name);
        });

        /* Configure all entities here. Example:

        builder.Entity<Question>(b =>
        {
            //Configure table & schema name
            b.ToTable(ProductServiceDbProperties.DbTablePrefix + "Questions", ProductServiceDbProperties.DbSchema);

            b.ConfigureByConvention();

            //Properties
            b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength);

            //Relations
            b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId);

            //Indexes
            b.HasIndex(q => q.CreationTime);
        });
        */
    }
}
